package com.ww.article.controller;

import com.ww.article.service.ApArticleService;
import com.ww.common.dtos.ResponseResult;
import com.ww.model.article.dtos.ArticleHomeDto;
import com.ww.model.article.pojos.ApArticle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/v1/article")
public class ApArticleController {
    @Autowired
    private ApArticleService apArticleService;
    /**
     * 加载首页文章
     */
    @PostMapping("/load")
    public ResponseResult<List<ApArticle>> load(@RequestBody ArticleHomeDto dto) {
        //1代表小于
        List<ApArticle> articles = apArticleService.loadApArticle(dto,1);
        return ResponseResult.okResult(articles);
    }
    /**
     * 加载更多,向后翻页。
     */
    @PostMapping("/loadmore")
    public ResponseResult<List<ApArticle>> loadMore(@RequestBody ArticleHomeDto dto){
        //1代表小于
        List<ApArticle> apArticles = apArticleService.loadApArticle(dto, 1);
        return ResponseResult.okResult(apArticles);
    }

    /**
     * 加载最新,刷新。
     */
    @PostMapping("/loadnew")
    public ResponseResult<List<ApArticle>> loadNew(@RequestBody ArticleHomeDto dto){
        //2代表大于
        List<ApArticle> apArticles = apArticleService.loadApArticle(dto, 2);
        return ResponseResult.okResult(apArticles);
    }
}
